#define _CRT_SECURE_NO_WARNINGS
#include"string.h"

namespace my_string
{
	void test1()
	{
		string s1;
		string s2 = "hello";
		cout << s1.c_str() << endl;
		cout << s2.c_str() << endl;


		string s3 = s2;
		s1 = s2;
		cout << s3.c_str() << endl;
		cout << s2.c_str() << endl;

	}

	void test2()
	{
		string s1 = "hello world";

		for (auto i : s1)
		{
			cout << i << " ";
		}
		cout << endl;

		string s2 = "ni hao";
		string::iterator it = s2.begin();
		while (it != s2.end())
		{
			cout << *it << " ";
			++it;
		}
		cout << endl;
	}

	void test3()
	{
		string s1;
		s1 += '1';
		s1 += '2';
		s1 += '3';
		s1 += '4';

		s1.push_back('9');
		s1.append("hello");
		s1 += "world";
		cout << s1.c_str() << endl;

	}

	void test4()
	{
		string s1 = "hello world";
		s1.insert(s1.size(), "00000");
		cout << s1.c_str() << endl;

		s1.insert(6, "00000");
		cout << s1.c_str() << endl;

		s1.insert(s1.size(), '8');
		cout << s1.c_str() << endl;

		s1.erase(9);
		cout << s1.c_str() << endl;

		//s1.insert(6, "777");
		//s1.erase(s1.size() - 1);

		//s1.insert(0, '1');

		cout << s1.c_str() << endl;
	}

	void test6()
	{
		string s1 = "hello world";
		string s2 = s1.substr(6);
		//cout << s2.c_str() << endl;
		cout << s2;
	}
}

void test5()
{
	char str1[] = "This is a simple string";
	char* str2;
	str2 = strstr(str1, "simple");

	printf("%s\n", str2);
	for (int i = 0; i < strlen("simple"); i++)
	{
		printf("%c", str2[i]);
	}
	printf("\n");

	str2 = strstr(str1, "are");
	printf("%s\n", str2);

}

int main()
{
	my_string::test6();
	//test5();
	return 0;
}